//
//  MyCarParameterView.m
//  SecondPage
//
//  Created by xiong qi on 13-5-6.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "MyCarParameterView.h"
#import "../../ResourceLoader/ResourceLoader/JSONKit.h"
#import "../../ResourceLoader/ResourceLoader/ResourceLoader.h"

@implementation MyCarParameterView
@synthesize dataSource;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
//        self.backgroundColor = [UIColor redColor];
        
        titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, frame.size.width-10, 20)];
        titleLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:17];
        [titleLabel setBackgroundColor:[UIColor clearColor]];
        [self addSubview:titleLabel];
        [titleLabel release];
        
        //基本参数
        baseParaLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 30, 104, 20)];
        baseParaLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
        baseParaLabel.textAlignment = NSTextAlignmentLeft;
        baseParaLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:17];
        [baseParaLabel setBackgroundColor:[UIColor clearColor]];
        [self addSubview:baseParaLabel];
        [baseParaLabel release];
        baseParaLabel.text = @"基本参数";
        

        parameterItemView1 = [[MyCarParameterItemView alloc] initWithFrame:CGRectMake(5, 60, frame.size.width, 20)];
        [self addSubview:parameterItemView1];
        [parameterItemView1 release];
        
        parameterItemView2 = [[MyCarParameterItemView alloc] initWithFrame:CGRectMake(5, 80, frame.size.width, 20)];
        [self addSubview:parameterItemView2];
        [parameterItemView2 release];
        
        parameterItemView3 = [[MyCarParameterItemView alloc] initWithFrame:CGRectMake(5, 100, frame.size.width, 20)];
        [self addSubview:parameterItemView3];
        [parameterItemView3 release];
        
        parameterItemView4 = [[MyCarParameterItemView alloc] initWithFrame:CGRectMake(5, 120, frame.size.width, 20)];
        [self addSubview:parameterItemView4];
        [parameterItemView4 release];
        
        
        
        //主要装备
        primaryLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 160, 104, 20)];
        primaryLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
        primaryLabel.textAlignment = NSTextAlignmentLeft;
        primaryLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:17];
        [primaryLabel setBackgroundColor:[UIColor clearColor]];
        [self addSubview:primaryLabel];
        [primaryLabel release];
        primaryLabel.text = @"主要装备";
        
        parameterItemView5 = [[MyCarParameterItemView alloc] initWithFrame:CGRectMake(5, 190, frame.size.width, 20)];
        [self addSubview:parameterItemView5];
        [parameterItemView5 release];
        
        parameterItemView6 = [[MyCarParameterItemView alloc] initWithFrame:CGRectMake(5, 210, frame.size.width, 20)];
        [self addSubview:parameterItemView6];
        [parameterItemView6 release];
        
        parameterItemView7 = [[MyCarParameterItemView alloc] initWithFrame:CGRectMake(5, 230, frame.size.width, 20)];
        [self addSubview:parameterItemView7];
        [parameterItemView7 release];
        
        parameterItemView8 = [[MyCarParameterItemView alloc] initWithFrame:CGRectMake(5, 250, frame.size.width, 20)];
        [self addSubview:parameterItemView8];
        [parameterItemView8 release];
        
//        {
//            
//            
//            //长宽高
//            sizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 50, 104, 20)];
//            sizeLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
//            sizeLabel.textAlignment = NSTextAlignmentLeft;
//            sizeLabel.font = [UIFont fontWithName:@"Arial" size:11];
//            [sizeLabel setBackgroundColor:[UIColor clearColor]];
//            [self addSubview:sizeLabel];
//            [sizeLabel release];
//            
//            //长宽高
//            wheelbaseLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 70, 104, 20)];
//            wheelbaseLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
//            wheelbaseLabel.textAlignment = NSTextAlignmentLeft;
//            wheelbaseLabel.font = [UIFont fontWithName:@"Arial" size:11];
//            [wheelbaseLabel setBackgroundColor:[UIColor clearColor]];
//            [self addSubview:wheelbaseLabel];
//            [wheelbaseLabel release];
//            
//            //长宽高
//            drivetypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 90, 104, 20)];
//            drivetypeLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
//            drivetypeLabel.textAlignment = NSTextAlignmentLeft;
//            drivetypeLabel.font = [UIFont fontWithName:@"Arial" size:11];
//            [drivetypeLabel setBackgroundColor:[UIColor clearColor]];
//            [self addSubview:drivetypeLabel];
//            [drivetypeLabel release];
//            
//            //长宽高
//            fuelLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 110, 104, 20)];
//            fuelLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
//            fuelLabel.textAlignment = NSTextAlignmentLeft;
//            fuelLabel.font = [UIFont fontWithName:@"Arial" size:11];
//            [fuelLabel setBackgroundColor:[UIColor clearColor]];
//            [self addSubview:fuelLabel];
//            [fuelLabel release];
//            
//            
//        }
//        
//        {
//            
//            
//            //长宽高
//            displacementLabel = [[UILabel alloc] initWithFrame:CGRectMake(119, 50, 104, 20)];
//            displacementLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
//            displacementLabel.textAlignment = NSTextAlignmentLeft;
//            displacementLabel.font = [UIFont fontWithName:@"Arial" size:11];
//            [displacementLabel setBackgroundColor:[UIColor clearColor]];
//            [self addSubview:displacementLabel];
//            [displacementLabel release];
//            
//            //长宽高
//            powerLabel = [[UILabel alloc] initWithFrame:CGRectMake(119, 70, 104, 20)];
//            powerLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
//            powerLabel.textAlignment = NSTextAlignmentLeft;
//            powerLabel.font = [UIFont fontWithName:@"Arial" size:11];
//            [powerLabel setBackgroundColor:[UIColor clearColor]];
//            [self addSubview:powerLabel];
//            [powerLabel release];
//            
//            transmissionLabel = [[UILabel alloc] initWithFrame:CGRectMake(119, 90, 104, 20)];
//            transmissionLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
//            transmissionLabel.textAlignment = NSTextAlignmentLeft;
//            transmissionLabel.font = [UIFont fontWithName:@"Arial" size:11];
//            [transmissionLabel setBackgroundColor:[UIColor clearColor]];
//            [self addSubview:transmissionLabel];
//            [transmissionLabel release];
//            
//            tireLabel = [[UILabel alloc] initWithFrame:CGRectMake(119, 110, 104, 20)];
//            tireLabel.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
//            tireLabel.textAlignment = NSTextAlignmentLeft;
//            tireLabel.font = [UIFont fontWithName:@"Arial" size:11];
//            [tireLabel setBackgroundColor:[UIColor clearColor]];
//            [self addSubview:tireLabel];
//            [tireLabel release];
//        }
        
    }
    return self;
}

-(void)RefreshParameterData:(FavoriteModuleView *)moduleview
{
    //@chenms @0826
    self.autoID = moduleview.autoID;
    
    NSString * selectstr = [NSString stringWithFormat:@"SELECT * FROM CollocateParameterTable where CollocateID=%d",moduleview.selectIndex];
    
    NSArray * array = [[MyCarSQLHelp getInstance] GetTableData:selectstr];
    
    if (array != nil && array.count >0) {
        self.dataSource = [array objectAtIndex:0];
    }
    [self SetData];
    
}

-(void)SetData
{
    NSDictionary * templateDic = self.dataSource;
    // @chenms@0906
    titleLabel.text = [templateDic objectForKey:CarInfo_Title];
    
    {
        [parameterItemView1 SetTitle:@"长×宽×高" AndContent:[templateDic objectForKey:CarInfo_Size]];
        [parameterItemView2 SetTitle:@"轴距" AndContent:[templateDic objectForKey:CarInfo_wheelbase]];
        [parameterItemView3 SetTitle:@"驱动方式" AndContent:[templateDic objectForKey:CarInfo_DriveType]];
        [parameterItemView4 SetTitle:@"工况油耗" AndContent:[templateDic objectForKey:CarInfo_Fuel]];
        
    }
    
    {
        [parameterItemView5 SetTitle:@"排气量" AndContent:[templateDic objectForKey:CarInfo_Displacement]];
        [parameterItemView6 SetTitle:@"最大功率" AndContent:[templateDic objectForKey:CarInfo_Power]];
        [parameterItemView7 SetTitle:@"变速箱" AndContent:[templateDic objectForKey:CarInfo_Transmission]];
        [parameterItemView8 SetTitle:@"轮胎" AndContent:[templateDic objectForKey:CarInfo_Tire]];
    }
}


-(void)dealloc
{
    self.dataSource = nil;
    self.autoID = nil;
    [super dealloc];
}

@end
